const jwtUtil = require('../utils/jwtUtils')
module.exports=class admin_dao extends require('../model/admin_mod'){

  static async getUsersByTypeAndChar(req,res){
    console.log(req.query)
    let query=req.query
    let data = await this.getUsersByTypeAndCharMod(query.type,query.inputText,query.CharType,
      query.currPage,query.pageNum)
    let total=await this.getUserByTypePageTotal(query.type,query.inputText,query.CharType)
    res.send({data,total:total[0].count})
  }

  /**
   * 发布通告
   * @param req
   * @param res
   * @returns {Promise<void>}
   */
  static async announce(req,res){
    let content=req.body.content
    let title=req.body.title
    let classes=req.body.class
    let results=await this.announceMod(content,title,classes)
    res.send(results)
  }

  static async getAllNotice(req,res){
      let pageNum=req.query.pageNum
      let currPage=req.query.currPage
      let data =await this.getAllNoticeMod(pageNum,currPage)
      let total=await this.getAllNoticeTotal()
     res.send({data,total:total[0].count})
  }

  /**
   * 删除通告
   * @param req
   * @param res
   * @returns {Promise<void>}
   * @constructor
   */
  static async DelectNotice(req,res){
    let result= await this.delUserDataMod(req.query.n_id)
    res.send(result)
  }

  /**
   * 根据n_id获取notice
   * @param req
   * @param res
   * @returns {Promise<void>}
   */
  static async getnoticeByid(req,res){
    let data=await this.getnoticeByidMod(req.query.n_id)
    res.send(data)
  }

  /**
   * 更新notice的内容
   * @param req
   * @param res
   * @returns {Promise<void>}
   * @constructor
   */
  static async UpdataNotice(req,res){
    let result=await this.UpdataNoticeMod(req.body.n_id,req.body.content)
    res.send(result)
  }

  /**
   * 获取班级列表
   * @param req
   * @param res
   * @returns {Promise<void>}
   */
  static async getclass(req,res){
    let data=await this.getclassMod()
    res.send(data)
  }

  /**
   * 教师获取自己班级的请假申请
   * @param req
   * @param res
   * @returns {Promise<void>}
   */
  static async getleave(req,res){
    let veritfy =await jwtUtil.verifysync(req.query.token,globalKey)
    let classArr=veritfy.classes.split(',')
    let data=await this.getleaveMod(classArr,req.query.currPage,req.query.pageNum)
    let total=await this.getleaveTotal(classArr)
    res.send({data,total:total[0].count})
  }

  /**
   * 修改请假管理的状态
   * @param req
   * @param res
   * @returns {Promise<void>}
   */
  static async updataLeaveState(req,res){
    let l_id=req.body.l_id
    let state=req.body.state
    let result=await this.updataLeaveStateMod(l_id,state)
    res.send(result)
  }

  static async addclasses(req,res){
    let classes=req.body.classes
    let college=req.body.college
    let result=await this.addclassesMod(classes,college)
    res.send(result)
  }

  /**
   * 获取已读通告人数
   */
  static async noticeread(req,res){
    let n_id=req.query.n_id
    let total=await this.noticereadMod(n_id)
    res.send({total:total[0].count})
  }
}
